home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / TCPTIMER.C < prev    next >
Text File  |  1993-08-09  |  1KB  |  52 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. int Tcp_retry = 5;
  11.  
  12. /* Timer timeout */
  13. void
  14. tcp_timeout(void *p)
  15. {
  16.     struct tcb *tcb = (struct tcb *)p;
  17.  
  18.     if(tcb == NULLTCB)
  19.         return;
  20.  
  21.     /* Make sure the timer has stopped (we might have been kicked) */
  22.     stop_timer(&tcb->timer);
  23.  
  24.     switch(tcb->state){
  25.     case TCP_TIME_WAIT:                /* 2MSL timer has expired */
  26.         close_self(tcb,NORMAL);
  27.         break;
  28.     default:
  29.         /* Retransmission timer has expired */
  30.         tcb->flags.retran = 1;    /* Indicate > 1  transmission */
  31.         tcb->backoff++;
  32.         if(Tcp_retry > 0) {
  33.             if((tcb->backoff > Tcp_retry && tcb->state != TCP_ESTABLISHED)
  34.               || (tcb->backoff > Tcp_retry * 5
  35.               && (tcb->state == TCP_ESTABLISHED || tcb->state == TCP_FINWAIT1))) {
  36.                 close_self(tcb,TIMEOUT);
  37.                 break;
  38.             }
  39.         }
  40.         tcb->snd.ptr = tcb->snd.una;
  41.  
  42.         /* Reduce slowstart threshold to half current window */
  43.         tcb->ssthresh = max(tcb->cwind / 2,tcb->mss);
  44.  
  45.         /* Shrink congestion window to 1 packet */
  46.         tcb->cwind = tcb->mss;
  47.         tcp_output(tcb);
  48.         break;
  49.     }
  50. }
  51.  
  52.